package org.redhat.auth.security.util;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;

/**
 * 管理CacheManager的封闭类
 * 
 * @author lingen.liu
 * 
 */
public class CacheManagerUtil {

	public static final String RESOURCES_CACHE_EXISTS = "isResourcesCacheExists";

	/**
	 * 获取用户缓存
	 * 
	 * @return
	 */
	public static Cache getUserCache() {
		return CacheManager.getInstance().getCache("userCache");
	}

	/**
	 * 获取资源缓存
	 * 
	 * @return
	 */
	public static Cache getResourceCache() {
		if (!CacheManager.getInstance().cacheExists("resourceCache")) {
			Cache cache = new Cache("resourceCache", 10000, true, false,
					1200000, 20000);
			CacheManager.getInstance().addCache(cache);
			return cache;
		}
		return CacheManager.getInstance().getCache("resourceCache");
	}
	
	
	/**
	 * 获取用户附加属性的缓存
	 * @return
	 */
	public static Cache getLoginParamCache(){
		if (!CacheManager.getInstance().cacheExists("loginParamCache")) {
			Cache cache = new Cache("loginParamCache", 10000, true, false,
					1200000, 20000);
			CacheManager.getInstance().addCache(cache);
		}
		return CacheManager.getInstance().getCache("loginParamCache");
	}
}
